// Here we export some useful types and functions for interacting with the Anchor program.
import { Account, getBase58Decoder, SolanaClient } from 'gill'
import { getProgramAccountsDecoded } from './helpers/get-program-accounts-decoded'
import { Curdapp, CURDAPP_DISCRIMINATOR, CURDAPP_PROGRAM_ADDRESS, getCurdappDecoder } from './client/js'
import CurdappIDL from '../target/idl/curdapp.json'

export type CurdappAccount = Account<Curdapp, string>

// Re-export the generated IDL and type
export { CurdappIDL }

export * from './client/js'

export function getCurdappProgramAccounts(rpc: SolanaClient['rpc']) {
  return getProgramAccountsDecoded(rpc, {
    decoder: getCurdappDecoder(),
    filter: getBase58Decoder().decode(CURDAPP_DISCRIMINATOR),
    programAddress: CURDAPP_PROGRAM_ADDRESS,
  })
}
